package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 */
public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书");
        System.out.println("请输入你要归还的书名: ");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int count = bookList.getUseSize();
        int i = 0;
        for ( i = 0; i < count; i++) {
            Book book = bookList.getBooks(i);
            if(book.getName().equals(name)){
                if (book.getBorrow() == true){
                    book.setBorrow(false);
                    System.out.println("归还成功");
                }else {
                    System.out.println(name+"不是该图书的书");
                }
                return;
            }
        }
        if (i == count){
            System.out.println("未找到"+name+"这本书");
        }
    }
}
